package com.ezbuy.common.helper;

import com.ezbuy.common.request.GrpcMapper;

import java.util.ArrayList;
import java.util.List;

public class ListMapper {

    public static <Grpc, Entity> List<Grpc> toGrpc(GrpcMapper<Grpc, Entity> mapper, List<Entity> entitys) {
        List<Grpc> grpcs = new ArrayList<>();
        for (Entity entity : entitys) {
            if (entity != null) {
                grpcs.add(mapper.toGrpc(entity));
            }
        }
        return grpcs;
    }

    public static <Grpc, Entity> List<Entity> fromGrpc(GrpcMapper<Grpc, Entity> mapper, List<Grpc> grpcs) {
        List<Entity> entitys = new ArrayList<>();
        for (Grpc grpc : grpcs) {
            if (grpc != null) {
                entitys.add(mapper.fromGrpc(grpc));
            }
        }
        return entitys;
    }


}
